﻿using KAKA.Domain;
using KAKA.Repository;
using Morus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace KAKA
{
    public class SiteAttribute : FilterAttribute, IResultFilter
    {
        public void OnResultExecuted(ResultExecutedContext filterContext)
        {
        }

        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            var httpContext = filterContext.HttpContext;

            var site = httpContext.Items[typeof(Site)];

            if (site == null)
            {
                var settings = IoC.Resolve<SettingRepository>();

                site = new Site
                {
                    SiteTitle = settings.GetByName(Setting.NAME_SITE_TITLE).Value
                };
                httpContext.Items[typeof(Site)] = site;
            }
        }
    }
}